package com.xiaoq.system.endpoint;

import java.util.Date;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xiaoq.coms.GenericResponse;
import com.xiaoq.system.entity.FeedbackEntity;
import com.xiaoq.system.service.IFeedbackService;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

@RestController
@RequestMapping(value="/api/v1/feedback")
public class FeedbackEndpoint {
	
	@Autowired
	private IFeedbackService feedbackSer;
	
	private static final Logger LOG = LoggerFactory.getLogger(FeedbackEndpoint.class);
	
	@ApiOperation(value = "添加一条反馈信息", notes = "添加一条反馈信息")
	@ApiResponses({ @ApiResponse(code = 200, response = GenericResponse.class, message = "添加一条反馈信息") })
	@PostMapping(value = "/{userId}", produces = { MediaType.APPLICATION_JSON_UTF8_VALUE })
	public ResponseEntity<?> addFeedback(@PathVariable(value="userId",required=false)@ApiParam(value="userId",required=false)String userId,@RequestParam(value="content",required=true)String content){
		if(StringUtils.isNoneEmpty(userId)){
			if(StringUtils.isNotEmpty(content)){
				FeedbackEntity feedback = new FeedbackEntity();
				feedback.setOperId(userId);
				feedback.setContent(content);
				feedback.setOpTime(System.currentTimeMillis());
				feedback.setType("1");
				feedbackSer.addFeedback(feedback);
				return GenericResponse.ok();
			}else{
				return GenericResponse.ng("反馈信息不能为空！");
			}
			
		}else{
			return GenericResponse.ng("请先登录,才可以反馈！");
		}
	}

}
